const getRouteOpts = (route) => {
  const { name, path, meta } = route;
  return {
    name,
    path,
    meta,
  };
};

export default {
  state: {
    // 面包屑
    breadCrumbList: [],
  },

  getters: {},

  mutations: {
    setBreadCrumb(state, route) {
      // 从matched中拼接面包屑
      state.breadCrumbList = [];
      route.matched.forEach((item, index) => {
        const opt =
          index === route.matched - 1
            ? getRouteOpts(route)
            : getRouteOpts(item);
        state.breadCrumbList.push(opt);
      });
      console.log("mutations", state.breadCrumbList);
    },

    // 清空面包屑
    clearBreadCrumb(state, path) {
      if (!state.breadCrumbList.length) return;
      const current = state.breadCrumbList[state.breadCrumbList.length - 1];
      if (current.path === path) return;
      state.breadCrumbList.splice(0, state.breadCrumbList.length);
    },
  },

  actions: {},
};
